<?php

namespace App\Api\Controllers;

use App\Api\Dao\GoodsCateDao;
use App\Api\Dao\GoodsDao;
use App\Api\Logic\GoodsLogic;
use App\Exceptions\ValidationException;
use Illuminate\Http\Request;

class GoodsController extends BaseController
{
    /**
     * 获取商品列表
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getGoodsList(Request $request,GoodsLogic $goodsLogic,GoodsDao $goodsDao){
        $param = $request->all();
        $goodsLogic->getGoodsList($param);
        $result = $goodsDao->getGoodsList($param);
        return $this->success($result);
    }

    /**
     * 获取商品的详情
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getGoodsInfo(Request $request,GoodsLogic $goodsLogic,GoodsDao $goodsDao){
        $param = $request->all();
        $goodsLogic->getGoodsInfo($param);
        $result = $goodsDao->getGoodsInfo(['id'=>$param['goods_id']]);
        return $this->success($result);
    }

    /**
     * 获取分类的列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function getCateList(Request $request,GoodsCateDao $goodsCateDao){
        $param = $request->all();
        $result = $goodsCateDao->getCateList($param);
        return $this->success($result);
    }
}
